package com.swak;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import io.netty.handler.codec.http.HttpResponseStatus;

/**
 * 系统常量
 *
 * @author: lifeng
 * @date: 2020/3/29 15:41
 */
public interface Constants {

	/**
	 * Path
	 */
	String PATH_SEPARATE = "/";
	String IDS_SEPARATE = ",";
	String MODULE_SEPARATE = ".";

	/**
	 * Http Path 配置项目
	 */
	String URL_PATH_SEPARATE = "/";
	String URL_PATH_VARIABLE_PRE = "{";
	String URL_PATH_VARIABLE_SUFFIX = "}";
	String URL_PATH_VARIABLE_PRE_X = ":";
	String URL_PATH_VARIABLE_SUFFIX_X = "";

	/**
	 * 跨域相关的配置
	 */
	String Cors_Ajax_Header = "X-Requested-With";
	String Cors_Content_Type_Header = "Content-Type";
	String Cors_Allowed_Origin_For_Dev = ".*";
	int Cors_Max_Age_Seconds_For_Dev = 60 * 60 * 24 * 30;

	/**
	 * 配置项前缀
	 */
	String APPLICATION_PREFIX = "spring.application";
	String VERTX_SERVER_PREFIX = "spring.vertx";
	String FLUX_SERVER_PREFIX = "spring.http-server";
	String REDIS_PREFIX = "spring.redis";
	String HTTP_CLIENT_PREFIX = "spring.http-client";
	String SECURITY_PREFIX = "spring.security";
	String MYBATIS_PREFIX = "spring.mybatis";
	String DATASOURCE_PREFIX = "spring.datasource";
	String ACTUATOR_METRICS = "spring.metrics";
	String ACTUATOR_ENDPOINT_WEB = "spring.endpoints.web";
	String ACTUATOR_TRACE = "spring.trace";
	String STORAGE_PREFIX = "spring.storage";
	String MOTAN_PREFIX = "spring.motan";
	String JOB_PREFIX = "spring.job";
	String RABBITMQ_PREFIX = "spring.rabbitmq";
	String ROCKETMQ_PREFIX = "spring.rocketmq";
	String MONGO_PREFIX = "spring.mongo";
	String EVENT_BUS_PREFIX = "spring.eventbus";
	String RXTX_PREFIX = "spring.rxtx";
	String AOP_PREFIX = "spring.aop";
	String ZOOKEEPER_PREFIX = "spring.zookeeper";
	String TCC_PREFIX = "spring.tcc";
	String Reliable_Msg_PREFIX = "spring.reliable-msg";
	String Sentinel_Prefix = "spring.sentinel";
	String MONITOR_PREFIX = "spring.monitor";
	String Application_Name = "spring.application.name";
	String Application_Profiles = "spring.profiles.active";

	/**
	 * 是/否/删除 - TINYINT
	 **/
//	byte YES = 1;
//	byte NO = 0;
//	byte DEL = -1;

	/**
	 * 默认编码
	 **/
	Charset DEFAULT_ENCODING = StandardCharsets.UTF_8;

	/**
	 * 缓存 (不建议使用)
	 **/
	@Deprecated
	int COOKIE_CACHE_TIMES = 60 * 60 * 24;

	/**
	 * 缓存 (不建议使用)
	 */
	@Deprecated
	String TOKEN_CACHE_NAME = "TOKENS";

	/**
	 * cookie
	 **/
	String DELETED_COOKIE_VALUE = "deleteMe";

	/**
	 * 服务地址
	 **/
	String ANYHOST = "0.0.0.0";
	String LOCALHOST = "127.0.0.1";
	String Multicast_Host = "224.0.0.121"; // 224.0.0.0 ~ 239.255.255.255
	String Broadcast_Host = "255.255.255.255";
	Integer Multicast_Port = 60001;
	Integer Multicast_Discovery_Times = 10; // 发送 Multicast 100 次，默认1分钟发送一次；前10分钟发送;

	/**
	 * 重定向
	 **/
	String REDIRECT_URL_PREFIX = "redirect:";

	/**
	 * 请求头部
	 **/
	String SUBJECT_NAME = "X-Subject";
	String VALIDATE_NAME = "X-Validate";
	String VALIDATE_Processed_NAME = "X-Validate-Processed";
	String TOKEN_NAME = "X-Token";
	String EXCEPTION_NAME = "x-Exception";
	String URL_NAME = "x-Url";
	String Platform_NAME = "X-Platform";
	String App_NAME = "X-App";
	String Open_NAME = "X-Open";

	/**
	 * method key
	 **/
	String ASYNC_SUFFIX = "Async";

	/**
	 * validate msg
	 **/
	String NOT_NULL_ERROR_MSG = "非空校验失败";
	String MAX_ERROR_MSG = "最大值校验失败";
	String MIN_ERROR_MSG = "最小值校验失败";
	String LENGTH_ERROR_MSG = "长度校验失败";
	String EMAIL_ERROR_MSG = "邮箱校验失败";
	String PHONE_NUM_ERROR_MSG = "手机号校验失败";
	String REGEX_ERROR_MSG = "正则校验失败";

	/**
	 * validate regex
	 **/
	String FIELD_REGEX = "^[a-zA-Z_]+\\w+$";
	String DATE_REGEX = "^[0-9]{4}\\-[0-9]{1,2}\\-[0-9]{1,2}$";
	String DIGIT_REGEX = "^\\d+(\\.\\d+)?$";
	String IP_REGEX = "\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b";
	String EMAIL_REGEX = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
	String PHONE_NUM_REGEX = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";

	/**
	 * permission
	 **/
	String SECURITY_OR_DIVIDER_TOKEN = "|";
	String SECURITY_AND_DIVIDER_TOKEN = ",";
	String SECURITY_WILDCARD_TOKEN = "*";
	String SECURITY_PART_DIVIDER_TOKEN = ":";

	/**
	 * Http Status
	 **/
	HttpResponseStatus FOUND = HttpResponseStatus.FOUND;
	HttpResponseStatus UNAUTHORIZED = HttpResponseStatus.UNAUTHORIZED;
	HttpResponseStatus NOT_FOUND = HttpResponseStatus.NOT_FOUND;
	HttpResponseStatus INTERNAL_SERVER_ERROR = HttpResponseStatus.INTERNAL_SERVER_ERROR;

	/**
	 * Invoker: 1 LocalMethod 、 2 异步
	 */
	byte OPERATORS_LOCAL = 1 << 1;
	byte OPERATORS_ASYNC = 1 << 2;

	/**
	 * 服务注册发现
	 */
	int DEFAULT_REGISTRY_RETRY_TIMES = 3;
	int DEFAULT_REGISTRY_RECONNECT_PERIOD = 3 * 1000;
	int DEFAULT_REGISTRY_RETRY_PERIOD = 5 * 1000;
	String REGISTRY_RETRY_TIMES_KEY = "retry.times";
	String REGISTRY_RETRY_PERIOD_KEY = "retry.period";
	String REGISTRY__LOCAL_FILE_CACHE_ENABLED = "file.cache";
	String REGISTRY_FILESAVE_SYNC_KEY = "save.file";
	String Application_KEY = "application";
	String Module_Key = "module"; // 现在添加这样一层
	String Service_Key = "service";
	String Category_Key = "category";
	String Server_Key = "server";
	String Subscribe_Any_Value = "*";
	String Heartbeat = "heartbeat";
	String Heartbeat_Timeout = "heartbeatTimeout";
	String Connection_Timeout = "connectionTimeout";
	String Timeout = "timeout";
	Integer Default_Connection_Timeout = 1 * 1000;
	Integer Default_Timeout = 3 * 1000;
	Integer Default_Heartbeat = 60 * 1000;
	Object HEARTBEAT_EVENT = null;
	String SIDE = "side";
	String CLIENT_SIDE = "client";
	String SERVER_SIDE = "server";
	String Bind_Host = "bind";
	String TwoWay = "twoWay";
	String Host_Name = "hostname";
	String Serialization_Key = "serialization";
	String Networker_Key = "networker";
	String SSL_keyPath = "sslKeyPath";
	String SSL_certPath = "sslCertPath";
	String Use_Quic = "useQuic"; // cs 模式可以选择使用 quic
	String Use_Udp = "useUdp"; // peer 模式才开启
	String Use_Udp_Multicast = "useUdpMulticast"; // 是 useUdp 的一个子项
	String Multicast_Host_Key = "multicastHost";
	String Multicast_Port_Key = "multicastPort";
	String Peer_Id = "peerId";
	String Discovery_Mode = "Multicast";
	String Discovery_Mode_Key = "DiscoveryMode";
	String Discovery_Multicast_Host = "224.0.0.101";
	String Discovery_Multicast_Host_Key = "DiscoveryMulticastHost";
	String Discovery_Multicast_Port_Key = "DiscoveryMulticastPort";
	String Discovery_Multicast_Discovery_Times_Key = "DiscoveryMulticastDiscoveryTimes";
	String PAYLOAD_KEY = "payload";
	int DEFAULT_PAYLOAD = 8 * 1024 * 1024; // 8M

	/**
	 * 日期时间格式
	 */
	String Only_Day_Format = "MMdd";
	String Day_Format = "yyyy-MM-dd";
	String Hour_Format = "yyyy-MM-dd HH";
	String Minute_Format = "yyyy-MM-dd HH:mm";
	String Second_Format = "yyyy-MM-dd HH:mm:ss";
	String Only_Minute_Format = "HH:mm";
	String Simple_Day_Format = "yy/MM/dd";

	/**
	 * 周几
	 */
	String[] Week_Days = { "周一", "周二", "周三", "周四", "周五", "周六", "周日" };
	String[] Week_Day2s = { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" };

	/**
	 * 保留ID
	 **/
	long ROOT = 0L;
	long INVALID_ID = -1;
	String STR_INVALID_ID = "-1";
	long Fix_Time = 1672502400000L; // 2023-01-01

	/**
	 * 指标
	 */
	String Metrics_Driver_Prefix = "Metrics:";
	String Metrics_Threads_Prefix = "Threads.";
	String Metrics_Schedule_Prefix = "Schedules.";
	String Metrics_Sql_Prefix = "Sqls.";
	String Metrics_Method_Prefix = "Methods.";

	/**
	 * 注册
	 */
	String Registry_Memory_Key = "memory";
	String Registry_Zookeeper_Key = "zookeeper";
	String Registry_Flux_Key = "flux";
	String Registry_Flux_Api_Key = "api";
	String Registry_Flux_Api_Method_Key = "method";
	String Registry_Flux_Api_Params_Key = "params";
	String Registry_Flux_Api_Module_Key = "module";
	String Registry_Flux_Api_Function_Key = "function";
	String Registry_Flux_Api_Describe_Key = "describe";
	String Registry_Flux_Service_Key = "service";
	String Registry_Flux_Service_Method_Key = "method";
	String Registry_Job_Key = "job";
	String Registry_Job_Worker_Key = "worker";
	String Registry_Job_Executer_Key = "Executer";
	String Registry_Job_Dispatcher_Key = "Dispatcher";
	String Registry_Job_Retryer_Key = "Retryer";
	String Registry_Monitor_Key = "monitor";
	String Registry_Telnet_Key = "telnet";
	String Registry_Telnet_Server_Key = "server";
	String Registry_ServerSn_Key = "server";
	String Registry_ServerSn_Sn_Key = "sn";
	
	/**
	 * 健康
	 */
	String Registry_Health = "health";

	/**
	 * 缓存
	 */
	String Cache_Global_Key = "_G_";
	String Cache_Security_Key = "_S_";
	String Cache_Hash_Key = "_H_";
	String Cache_List_Key = "_L_";
	String Cache_Set_Key = "_E_";
	String Cache_Separate_Key = ":"; // 以前是 #, 现在改为:
	int Cache_Global_Idle = 60 * 60 * 24; // 默认缓存一天
	int Cache_Security_Idle = 1800; // 30 分钟

	/**
	 * Func
	 */
	short Route_Func_Metrics = 1 << 0;
	short Route_Func_Result = 1 << 1;
	short Route_Func_Security = 1 << 2;
	short Route_Func_Method_Cache = 1 << 3;
	short Route_Func_Param_Parse = 1 << 4;
	short Route_Func_Param_Cache = 1 << 5;
	short Route_Func_File_Upload = 1 << 6;
	short Route_Func_Invoke = 1 << 7;

	/**
	 * 可用的核心线程数
	 */
	int Available_Processors = Runtime.getRuntime().availableProcessors();

	/**
	 * CACHE
	 */
	int CACHE_DEFAULT_LIFE_TIME = -1; // 默认不过期
	boolean CACHE_DEFAULT_IDEA_LIFE = true; // 默认不过期
}
